# @before-stub-for-debug-begin
from python3problem24 import *
from typing import *
# @before-stub-for-debug-end

#
# @lc app=leetcode.cn id=24 lang=python3
#
# [24] 两两交换链表中的节点
#
class ListNode:
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next
# @lc code=start
# Definition for singly-linked list.

class Solution:
    def swapPairs(self, head: ListNode) -> ListNode:
        newHead = preNode = ListNode(0, head)
        temp = head
        while temp is not None and temp.next is not None:
            preNode.next = temp.next
            nextNode = temp.next.next
            temp.next.next = temp
            temp.next = nextNode
            preNode = temp
            temp = temp.next
        return newHead.next

# @lc code=end

